package com.qztech.sdk.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.util.DisplayMetrics;
import android.view.WindowManager;
import android.widget.TextView;

import com.qztech.sdk.R;
import com.qztech.sdk.ui.adapter.FileAdapter;

/**
 * Created by zhb on 2018/10/31.
 */

public class ListDialog extends Dialog {

    TextView mTvTitle;

    RecyclerView mRecyclerView;

    public ListDialog(@NonNull Context context) {
        super(context, R.style.dialog);
        initView();
    }

    @Override
    public void setContentView(@LayoutRes int layoutResID) {
        super.setContentView(layoutResID);
    }

    @Override
    public void onDetachedFromWindow() {
        super.onDetachedFromWindow();
    }

    private void initView() {
        setContentView(R.layout.dialog_list);
        setCanceledOnTouchOutside(true);

        mRecyclerView = findViewById(R.id.recyclerView);
        mTvTitle = findViewById(R.id.tvtitle);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
        mRecyclerView.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL));
    }

    @Override
    public void show() {
        super.show();
        DisplayMetrics dm = getContext().getResources().getDisplayMetrics();
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.width = (int)(dm.widthPixels * 0.8);
        lp.height = 700;
        getWindow().setAttributes(lp);
    }

    public void setTitle(String title) {
        mTvTitle.setText(title);
    }

    public void setAdapter(FileAdapter adapter) {
        mRecyclerView.setAdapter(adapter);
    }
}
